<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of settings
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Email_template extends MY_Controller {

    //put your code here


    function email_template() {
        parent :: __construct();
        $this->template->set_theme('admin');
        $this->template->set_layout('admin_layout');
        $this->load->model('email_template_model');
        $this->commoncall->check_admin_login();
    }

//---------------Get All Templates---------------------
    function index() {
        $data['emailtemp'] = $this->email_template_model->get_templates();
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_email_template', $data);
    }

//-----------Get a Template By template Id-----------------------
    function get_tempalate() {
        $data['emailtemp'] = $this->email_template_model->get_templates();
        if ($this->input->post('get_value')) {
            $this->form_validation->set_rules('email_tempalte', 'email_tempalte', 'required|xss_clean');
            $templateID = $this->input->post('email_tempalte');
            if ($this->form_validation->run()) {
                $data['row']['info'] = $this->email_template_model->get_template($templateID);
                $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                        ->set_partial('admin_header', 'header/admin_header')
                        ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                        ->build('pages/admin_email_template', $data);
            } else {
                $this->session->set_flashdata('message', 'Choose Template type');
                redirect('admin/email_template', $data);
            }
        }
    }

//----------------Update Template------------------------------
    function update_template() {
        if ($this->input->post('update_template')) {
            $this->form_validation->set_rules('temp_detail', 'temp_detail', 'required|xss_clean');
            $this->form_validation->set_rules('temp_id', 'template_id', 'required|xss_clean');
            $templateID = trim($this->input->post('temp_id'));
            $template_description = trim($this->input->post('temp_detail'));
            if ($this->form_validation->run()) {
                $this->email_template_model->update_template($template_description, $templateID);
                $this->session->set_flashdata('message', 'Template Updated Sucessfully');
                redirect('admin/email_template');
            }
        }
        $this->session->set_flashdata('message', 'Please Choose a Template!');
        redirect('admin/email_template/');
    }

}

?>